package com.kangye.enterprise.frontdesk.controller;

import com.kangye.enterprise.frontdesk.entity.Attention;
import com.kangye.enterprise.frontdesk.service.AttentionService;
import com.kangye.enterprise.frontdesk.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: enterprise
 * @description:关注表的操作
 * @author: 索腾龙
 * @create: 2021-05-31 14:10
 **/
@RestController
@CrossOrigin
@RequestMapping("/attention")
public class AttentionController {
    @Autowired
    private AttentionService attentionService;
    //政策即时推送(未关注) 选择部门关注  点击确定(索腾龙写)
    @RequestMapping("/addAttention")
    public String   addAttention(String attentionUsersid ,String attentionDepartmentname,String attentionRegionname){
        //用数组接收,逗号分割
        String [] strArray = attentionUsersid.split(",");
        String [] strArray1 = attentionDepartmentname.split(",");
        String [] strArray2 = attentionRegionname.split(",");
        //创建list对象
        List<Attention> list = new ArrayList<>();
        //循环数组长度
        for (int i = 0;i<strArray.length;i++){
            Attention attention = new Attention();
            attention.setAttentionUsersid(Integer.valueOf(strArray[i]));
            attention.setAttentionDepartmentname(strArray1[i]);
            attention.setAttentionRegionname(strArray2[i]);
            list.add(attention);
        }
        Integer code = attentionService.addAttention(list);
        if (code>0){
            return "200";
        }else {
            return "201";
        }
    }
    //查询用户关注的信息(索腾龙写)
    @RequestMapping("/selAttention")
    public ViewJsonObject<Attention> selAttention(Integer attentionUsersid){
        return attentionService.selAttention(attentionUsersid);
    }
    //点击取消关注 删除这条消息(索腾龙写)
    @RequestMapping("/delAttention")
    public String delAttention(Integer attentionId){
        Integer code = attentionService.delAttention(attentionId);
        if (code>0){
            return "200";
        }else {
            return "201";
        }
    }
}